package com.hoongs.v1.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hoongs.v1.utils.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Repository
@TableName(value = "article")
public class Article {

    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    @NotBlank(message = "请输入文章标题")
    private String title;

    @TableField(value = "cover_img")
    private String coverImg;    // 文章封面

    private String summary;     // 摘要

    @NotBlank(message = "请输入内容")
    private String content;     // 文章内容

    @TableField(value = "pub_id")
    private String pubId;      // 发布人id

    @TableField(value = "pub_name")
    private String pubName;      // 发布人名称

    @NotBlank(message = "请选择文章状态")
    private String status;         // 文章状态 0.未发布 1.已发布 2. 已下架
    @NotBlank(message = "请选择文章标签")

    private String tag;         // 文章标签(id)
    @NotBlank(message = "请选择文章分类")

    private String category;    // 文章分类(id)

    private int views = 0;          // 浏览次数

    private int likes = 0;          // 点赞次数

    @TableField(value = "is_comment")
    private String isComment  = "0";      // 评论开启

    @TableField(value = "is_top")
    private String isTop = "0";          // 是否置顶

    @TableField(value = "is_nice")
    private String isNice  = "0";          // 是否精品

    private String comments;    // 评论(id)

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private LocalDateTime createTime;       // 发布时间

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;    // 更新时间

}
